package com.core.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.core.config.crud.CrudServiceImpl;
import com.core.system.dao.SystemDictItemMapper;
import com.core.system.service.ISystemDictItemService;
import com.pojo.dto.SystemDictItemDto;
import com.pojo.entity.SystemDictItemEntity;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 系统字典条目表 服务实现类
 * </p>
 *
 * @author hewei
 * @since 2023-12-31
 */
@Service
public class SystemDictItemServiceImpl extends CrudServiceImpl<SystemDictItemMapper, SystemDictItemEntity, SystemDictItemDto> implements ISystemDictItemService {

    @Override
    public LambdaQueryWrapper<SystemDictItemEntity> getLambdaQueryWrapper(Map<String, Object> paramMap) {
        LambdaQueryWrapper<SystemDictItemEntity> wrapper = Wrappers.lambdaQuery(SystemDictItemEntity.class);
        wrapper.select(SystemDictItemEntity::getId,
                SystemDictItemEntity::getDictItemName,
                SystemDictItemEntity::getDictItemValue,
                SystemDictItemEntity::getDictTypeId,
                SystemDictItemEntity::getDictDesc,
                SystemDictItemEntity::getSort);
        Object dictItemName = paramMap.get("dictItemName");
        Object dictItemValue = paramMap.get("dictItemValue");
        Object dictTypeId = paramMap.get("dictTypeId");
        Object dictTypeIds = paramMap.get("dictTypeIds");
        if (dictTypeIds instanceof List<?>){
            List<?> dictTypeIdsList = (List<?>)dictTypeIds;
            wrapper.in(!dictTypeIdsList.isEmpty(),SystemDictItemEntity::getDictTypeId,dictTypeIdsList);
        }

        wrapper.like(ObjectUtils.isNotEmpty(dictItemName),SystemDictItemEntity::getDictItemName,dictItemName);
        wrapper.eq(ObjectUtils.isNotEmpty(dictTypeId),SystemDictItemEntity::getDictTypeId,dictTypeId);
        wrapper.like(ObjectUtils.isNotEmpty(dictItemValue),SystemDictItemEntity::getDictItemValue,dictItemValue);
        wrapper.orderByDesc(SystemDictItemEntity::getSort);
        return wrapper;
    }

    @Override
    public void verify(SystemDictItemDto dto) {
    }
}
